﻿using System;
using System.Gadgets;
using ScriptFX;
using ScriptFX.Net;
using System.DHTML;

namespace MythtvGadget
{
    public delegate void GetStatusCompletedCallback(MythtvStatusResult result);

    public class MythtvStatus
    {
        public static void GetStatus(GetStatusCompletedCallback callback)
        {
            string uri = Settings.StatusUrl + "xml";

            try
            {
                HTTPRequest searchRequest = HTTPRequest.CreateRequest(uri, HTTPVerb.GET);

                searchRequest.Invoke
                    (
                        delegate(HTTPRequest request, object context)
                        {
                            MythtvStatusResult searchResult = new MythtvStatusResult(request.Response);
                            callback(searchResult);
                        },
                        null
                    );
            }
            catch (Exception)
            {
                DOMElement cp = Document.GetElementById("contentpanel");
                cp.InnerHTML = "Error";
            }
        }
    }
}
